import nattyFetch from 'natty-fetch';

import { Toast } from 'saltui';
import Loading from 'components/loading';

//引用定义的链接
import { urlPrefix, isDev,URLS,nodataIcon } from './variables';

// See https://github.com/Jias/natty-fetch for more details.
//数据交互设置
const context = nattyFetch.context({
  mockUrlPrefix: urlPrefix,
  urlPrefix,
  mock: isDev,
  // jsonp: true,
  withCredentials: false,
  traditional: true,
  header:{
    Authorization:'Bearer '+getLoginUserInfo().token,
  },
  data: {
    _tb_token_: '',
  },
  timeout: 0,
  didFetch: () => Toast.hide(),
  // 请按照需要开启
  fit(response) {
    return {
      success: response.success,
      content: response.content,
      error: {
        errorMsg: response.errorMsg,
        errorCode: response.errorCode,
        errorLevel: response.errorLevel,
      },
    };
  },
});
//设置访问的方法
context.create('QuesModuleAPI', {
  getSomeInfo: {
    mockUrl: 'query/getSomeInfo.json',
    url: 'query/getSomeInfo.json',
    willFetch() {
      Toast.show({
        type: 'loading',
        content: 'Loading',
      });
    },
  },
  entityIsExist: {
    url: URLS.entityIsExist,
    method:'POST',
    willFetch() {
      
    },
  },
  saveQues: {
    url: URLS.saveQues,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  getDingQuesForm: {
    mockUrl:'query/getDingQuesForm.json',
    url: URLS.getDingQuesForm,
    method:'GET',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  getBackReason: {
    url: URLS.getBackReason,
    method:'GET',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  getDingQuesInfo: {
    mockUrl:'query/getDingQuesInfo.json',
    url: URLS.getDingQuesInfo,
    method: 'GET',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  answerEdit: {
    url: URLS.answerEdit,
    method:'POST',
    postDataFomat: 'FORM',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  getSubmittedReports: {
    mockUrl:URLS.getSubmittedReports,
    url: URLS.getSubmittedReports,
    method:'GET',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  getReportInfo: {
    mockUrl:'report/getReportInfo.json',
    url: URLS.getReportInfo,
    method: 'GET',
/*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  getReportForm: {
    mockUrl:'report/getReportForm.json',
    url: URLS.getReportForm,
    method: 'GET',
/*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  getTeamList: {
    mockUrl:'report/getTeamList.json',
    url: URLS.getTeamList,
    method: 'GET',
/*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },
  delReport: {
    url: URLS.delReport,
    method:'POST',
    postDataFomat: 'FORM',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  saveReport: {
    url: URLS.saveReport,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  saveReportComment: {
    url: URLS.saveReportComment,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },
  demoView: {
    url: URLS.demoView,
    method:'GET',
/*    header:{'content-Type':'application/x-www-form-urlencoded'},*/
    willFetch() {
       Toast.show({
        content: <Loading />
      });
    },
  },



  //更新问卷发布状态
  updateQuesPublish:{
    url: URLS.updateQuesPublish,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },
  //删除问卷
  deletQuesById:{
    url: URLS.deletQuesById,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },
  //查询问卷信息
  getQuesInfoById:{
    url: URLS.getQuesInfoById,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },
  //保存设计
  saveDesign :{
    url: URLS.saveDesign,
    method:'POST',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },
  //获取题目
  getQuestTopic :{
    url: URLS.getQuestTopic,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },
  getUserName :{
    url: URLS.getUserName,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },
  //回退问卷
  quesBack :{
    url: URLS.quesBack,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },

  //问卷统计详情
  getStatistics :{
    url: URLS.getStatistics,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },

getOptionDetail :{
    url: URLS.getOptionDetail,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },

  getRankingList :{
    url: URLS.getRankingList,
    method:'GET',
    willFetch() {
      Toast.show({
        content: <Loading />
      });
    },
  },

telSendMessage: {
    url: URLS.telSendMessage,
    method: 'POST',
    postDataFomat: 'FORM',
    willFetch() {
       Toast.show({
        type: 'loading',
        content: '提醒发送中...',
      });
    },
  },
});

export default context.api;
